﻿using System;
using Microsoft.VisualStudio.TemplateWizard;
using System.Collections.Generic;
using System.IO;

namespace TPG.SharePoint.Workflow.Templates
{
    public class AssociationFormWizard
        : IWizard
    {
        bool _useCodeSeparation = false;

        public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem)
        {
        }

        public void ProjectFinishedGenerating(EnvDTE.Project project)
        {
        }

        public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
        {
        }

        public void RunFinished()
        {
        }

        public void RunStarted(object automationObject, 
            Dictionary<string, string> replacementsDictionary, 
            WizardRunKind runKind, object[] customParams)
        {
            if (runKind == WizardRunKind.AsNewItem)
            {
                if (replacementsDictionary.ContainsKey("USE_CODESEPARATION"))
                {
                    _useCodeSeparation = true;
                }
            }
        }

        public bool ShouldAddProjectItem(string filePath)
        {
            string fileName = Path.GetFileName(filePath);
            if (String.Equals(
                fileName, "AssociationForm.aspx", StringComparison.OrdinalIgnoreCase))
            {
                return _useCodeSeparation == false;
            }
            if (String.Equals(
                fileName, "AssociationForm_cb.aspx", StringComparison.OrdinalIgnoreCase))
            {
                return _useCodeSeparation == true;
            }
            if (String.Equals(
                fileName, "CodeBehind.cs", StringComparison.OrdinalIgnoreCase))
            {
                return _useCodeSeparation == true;
            }
            return false;
        }
    }
}
